/**
 * 文件名：ThymeleafController
 * 版权：Copyright 2017-2022 CMCC All Rights Reserved.
 * 描述：
 */

package com.hand.project.controller;

import com.hand.project.dto.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 *
 *
 *
 * @author shuai.wang02@hand-china.com
 * @version 1.0
 * @date 2018/11/22 20:59
 */
@Controller
@RequestMapping
public class ThymeleafController {

    @GetMapping("/index")
    public ModelAndView index() {
        ModelAndView view = new ModelAndView();
        // 设置跳转的视图 默认映射到 src/main/resources/templates/{viewName}.html
        view.setViewName("index");
        // 设置属性
        view.addObject("title", "我的第一个WEB页面");
        view.addObject("desc", "欢迎进入battcn-web 系统");
        User user = new User();
        user.setUserName("唐亚峰");
        user.setPassWord("1837307557@qq.com");
        user.setArea("北京");
        view.addObject("user", user);
        return view;
    }

    @GetMapping("/index1")
    public String index1(HttpServletRequest request) {
        // 设置属性
        request.setAttribute("title", "我的第一个WEB页面");
        request.setAttribute("desc", "欢迎进入battcn-web 系统");
        User user = new User();
        user.setUserName("唐亚峰");
        user.setPassWord("1837307557@qq.com");
        user.setArea("北京");
        request.setAttribute("user", user);
        // 返回的 index 默认映射到 src/main/resources/templates/xxxx.html
        return "index";
    }
}
